/*
 * Room.h
 *
 *  Created on: 30.10.2013
 *      Author: ulgish
 */

#ifndef ROOM_H_
#define ROOM_H_

#include <pthread.h>
#include <unistd.h>
#include <lab3/Thinker.h>
namespace DT {

class Room {
protected:
	pthread_mutex_t* forks;
	bool* forksUsed;
	int* idOfThinkers;
	int currentCountOfThinkers;
	int currentCountOfWaitingThinkers;
	pthread_mutex_t mutexOfCount;
	int maxCountOfThinkers;
	bool closed;
private:
	void addCount(bool isWaiting);
	void subCount(bool isWaiting);
	int getNumberOfNextFork(int i);

	Room (const Room& orig);
public:
	Room(){};
	Room(const int& maxCount);
	void feed(const int& timeOfFeeding, const Thinker* thinker);
	bool isOpen(){
		return !closed;
	}
	void close(){
		closed = true;
	}
	void open(){
		closed = false;
	}
	void print();
	virtual ~Room();
};

}

#endif /* ROOM_H_ */
